/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-11-27     Administrator       the first version
 */
#ifndef APPLICATIONS_ACTIONQUEUE_ACTION_QUEUE_H_
#define APPLICATIONS_ACTION_QUEUE_ACTION_QUEUE_H_

#include <rtdef.h>

#ifdef __cplusplus
extern "C" {
#endif


#define MOTOR_FUNC 1
#define PUMP_FUNC 1

#define TOTAL_AQ_NUM 5

enum
{
  MODE_SLAVE,
  MODE_AUTO
};

enum
{
MODE_POS,
SW_MODE,
TIME_MODE,
MODE_AD_POS,
ADVANCED_DIS_MODE
};


enum
{
MASTER_SEND_TASK,
SLAVE_RECEIVE_TASK,
SLAVE_COMPLETE_TASK,
MASTER_RECEIVE_SLAVE_COMPLETE_INFO,
};

typedef struct
{
    rt_uint32_t time;
    rt_uint8_t sw;
}MODE_TIME;

typedef struct
{
    rt_uint8_t speedSelect;
    rt_uint8_t posNo;
}MODE_ADVANCED_POS;

typedef struct
{
    rt_uint8_t speedSelect;
    rt_uint8_t distance;
}MODE_ADVANCED_DIST;

typedef union
{
    rt_uint8_t posNo;
    rt_uint8_t sw;
    MODE_TIME mode_time;
    MODE_ADVANCED_POS ad_pos;
    rt_uint32_t distance;
    MODE_ADVANCED_DIST ad_dis;
}ACT_INFO;

typedef struct ACT_QUE
{
    rt_uint8_t devNo;
    rt_uint8_t actMode;
    ACT_INFO actInfo;
    struct ACT_QUE *next;
}ACT_QUE;

typedef struct Action
{
    rt_uint8_t devNo;
    rt_uint8_t actMode;
    ACT_INFO actInfo;
}Action;

class ActionQueue
{
private:
    rt_uint8_t Mode;
    rt_uint32_t total_step;
    rt_uint32_t remaining_step;
    rt_uint8_t current_step;
    uint8_t action_queue_num;
    uint8_t curTask[8];
public:
    ActionQueue(int _No);
    virtual ~ActionQueue();
public:
    void AddTaskToMyDev(uint8_t devNo);
    uint8_t SendTaskToTargetBoard(uint8_t devNo);
    void SetActQueTotalStep(uint8_t total_step);
    void ActOneStep();
    void Process(void *parameter);
    uint8_t SendTaskMsgToTargetBoard(uint8_t devNo,uint8_t* buf);
    void WaitTaskMsgAnswer(uint8_t devNo);
    void demoInit();
    void CAN_Send(uint8_t *p,uint8_t dataLenth,uint32_t ExtID);
};

extern ActionQueue ActQue_1;

extern void (*Action_Queue_Task_Ptr[21]) (void *parameter);

extern void AQ0_Task(void *parameter);
extern void AQ1_Task(void *parameter);
extern void AQ2_Task(void *parameter);
extern void AQ3_Task(void *parameter);
extern void AQ4_Task(void *parameter);
extern void AQ5_Task(void *parameter);
extern void AQ6_Task(void *parameter);
extern void AQ7_Task(void *parameter);
extern void AQ8_Task(void *parameter);
extern void AQ9_Task(void *parameter);
extern void AQ10_Task(void *parameter);
extern void AQ11_Task(void *parameter);
extern void AQ12_Task(void *parameter);
extern void AQ13_Task(void *parameter);
extern void AQ14_Task(void *parameter);
extern void AQ15_Task(void *parameter);
extern void AQ16_Task(void *parameter);
extern void AQ17_Task(void *parameter);
extern void AQ18_Task(void *parameter);
extern void AQ19_Task(void *parameter);
extern void AQ20_Task(void *parameter);

#ifdef __cplusplus
}
#endif


#endif /* APPLICATIONS_ACTIONQUEUE_ACTION_QUEUE_H_ */
